package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.vo.PtSysScoreVo;
import com.ruoyi.system.domain.bo.PtSysScoreBo;
import com.ruoyi.system.service.IPtSysScoreService;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiOperation;

/**
 * 实验成绩Controller
 *
 * @author ruoyi
 * @date 2022-03-26
 */
@Validated
@Api(value = "实验成绩控制器", tags = {"实验成绩管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/score")
public class PtSysScoreController extends BaseController {

    private final IPtSysScoreService iPtSysScoreService;

    /**
     * 查询实验成绩列表
     */
    @ApiOperation("查询实验成绩列表")
    @PreAuthorize("@ss.hasPermi('system:score:list')")
    @GetMapping("/list")
    public TableDataInfo<PtSysScoreVo> list(@Validated(QueryGroup.class) PtSysScoreBo bo, PageQuery pageQuery) {
        return iPtSysScoreService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出实验成绩列表
     */
    @ApiOperation("导出实验成绩列表")
    @PreAuthorize("@ss.hasPermi('system:score:export')")
    @Log(title = "实验成绩", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@Validated PtSysScoreBo bo, HttpServletResponse response) {
        List<PtSysScoreVo> list = iPtSysScoreService.queryList(bo);
        ExcelUtil.exportExcel(list, "实验成绩", PtSysScoreVo.class, response);
    }

    /**
     * 获取实验成绩详细信息
     */
    @ApiOperation("获取实验成绩详细信息")
    @PreAuthorize("@ss.hasPermi('system:score:query')")
    @GetMapping("/{id}")
    public AjaxResult<PtSysScoreVo> getInfo(@ApiParam("主键")
                                                  @NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iPtSysScoreService.queryById(id));
    }

    /**
     * 新增实验成绩
     */
    @ApiOperation("新增实验成绩")
    @PreAuthorize("@ss.hasPermi('system:score:add')")
    @Log(title = "实验成绩", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody PtSysScoreBo bo) {
        return toAjax(iPtSysScoreService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改实验成绩
     */
    @ApiOperation("修改实验成绩")
    @PreAuthorize("@ss.hasPermi('system:score:edit')")
    @Log(title = "实验成绩", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody PtSysScoreBo bo) {
        return toAjax(iPtSysScoreService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除实验成绩
     */
    @ApiOperation("删除实验成绩")
    @PreAuthorize("@ss.hasPermi('system:score:remove')")
    @Log(title = "实验成绩" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@ApiParam("主键串")
                                       @NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iPtSysScoreService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
